package application;

import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ControlPanelView extends JPanel
{
	// Components
	protected CanvasView canvas;
	protected ControlPanelController CPcontroller;
	protected JButton clearButton;
	protected JComboBox colorBox;
	
	/** 
	 * Constructor with a clear button to clear the canvas and a combo box
	 * to select the pen color
	 * 
	 * @param c references to the associated CanvasView
	 */
	public ControlPanelView(CanvasView c)
	{
		if(c == null)
			throw new IllegalArgumentException();
		
		canvas = c;
		clearButton = new JButton("Clear");
		add(clearButton);
		add(new JLabel("Pen color"));
		colorBox = new JComboBox();
		colorBox.addItem("Black");
		colorBox.addItem("Blue");
		colorBox.addItem("Red");
		colorBox.addItem("Yellow");
		add(colorBox);
		ControlPanelController CPcontroller = new ControlPanelController(canvas);
		addControlPanelListener(CPcontroller);
	}
	
	  /**
	   * Registers a ControlPanelController with this view's components.
	   * 
	   * This is implemented separately from createControlPanelController() in the
	   * event that a view subclass requires different listener registration for
	   * the components displayed on that view.
	   * 
	   * @param listener controller to register
	   */
	  protected void addControlPanelListener(ControlPanelController listener)
	  {
		  if( listener != null )
		  {
			  clearButton.addActionListener((ActionListener)listener);
			  colorBox.addItemListener((ItemListener)listener);
		  }
		  else
			  throw new IllegalArgumentException();
	  }// end protected void addControlPanelListener( EventListener )
}
